#### Assumptions

### Linerarity
plot(yasli$total_lonliness, yasli$Total_Fraility,
     xlab = "Loneliness (X)",
     ylab = "Frailty (M)",
     main = "Linearity Check: Loneliness → Frailty",
     pch=19, col = "grey40")
abline(lm(Total_Fraility ~ total_lonliness, data = yasli), col = "blue", lwd = 2)

plot(yasli$Total_Fraility, yasli$Total_QoL,
     xlab = "Frailty (M)",
     ylab = "Quality of Life (Y)",
     main = "Linearity Check: Frailty → QoL",
     pch = 19, col = "grey40")
abline(lm(Total_QoL ~ Total_Fraility, data = yasli), col = "blue", lwd = 2)



turkiye <- subset(yasli, country_n == 0)
almanya <- subset(yasli, country_n == 1)

# Türkiye için
m1_tr <- lm(Total_Fraility ~ total_lonliness, data = turkiye)
m2_tr <- lm(Total_QoL ~ total_lonliness + Total_Fraility, data = turkiye)

# Almanya için
m1_de <- lm(Total_Fraility ~ total_lonliness, data = almanya)
m2_de <- lm(Total_QoL ~ total_lonliness + Total_Fraility, data = almanya)




summary(m1_tr)
summary(m2_tr)
summary(m1_de)
summary(m2_de)



par(mfrow=c(2,2))
plot(m1_tr)
plot(m2_tr)
plot(m1_de)
plot(m2_de)


library(lmtest)
bptest(m1_tr)
bptest(m2_tr)
bptest(m1_de)
bptest(m2_de)

shapiro.test(m1_tr$residuals)
shapiro.test(m2_tr$residuals)
shapiro.test(m1_de$residuals)
shapiro.test(m2_de$residuals)




lmtest::dwtest(m1_tr)
lmtest::dwtest(m2_tr)



colnames(yasli)

covars <- yasli[, c("Total_Fraility", "total_lonliness", "sex_n", "age_t2", "marital_n", "edu_n", "income_n")]
cor_matrix <- round(cor(covars, use = "complete.obs"), 3)
cor_matrix




library(car)
vif(lm(Total_QoL ~ Total_Fraility + total_lonliness + sex_n + age_t2 + marital_n + edu_n + income_n, data = yasli))
